package ivansalvadori.diariopushweb.view.security;


import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.Session;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;
import org.apache.wicket.request.component.IRequestableComponent;

public class AuthStrategy implements IAuthorizationStrategy {

	@Override
	public boolean isActionAuthorized(Component arg0, Action arg1) {
		return true;

	}

	@Override
	public <T extends IRequestableComponent> boolean isInstantiationAuthorized(
			Class<T> comp) {

		if (!Page.class.isAssignableFrom(comp)) {
			return true;
		}
		if (!SecurePage.class.isAssignableFrom(comp)) {
			return true;
		}
		if (((MySession) Session.get()).getUsuario() == null) {
			throw new RestartResponseAtInterceptPageException(LoginPage.class);
		}
		return true;

	}

}